package com.beans.bean;

import com.model.User;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
public class UserBeans {
    @Bean(name="user1")  //将当前方法返回的对象存储到spring中，默认bean是方法名
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public User getUser(){
        User user=new User();
        user.setId(1);
        user.setName("张三");
        user.setPassword("123456");
        return user;
    }

    @Bean(name="user2")
    public User getUser2(){
        User user=new User();
        user.setId(2);
        user.setName("李四");
        user.setPassword("456");
        return user;
    }
}
